import { Space, Button,message } from 'antd';
import { useState } from 'react'
import EditOrderModal from './EditOrderModal';
import {closeOrderById,confirmOrderById } from '../../../../api/OrderApi'

export default function Btns(props: any) {
    const [isModalOpen, setIsModalOpen] = useState(false);

    console.log('props.value---btns',props.value);
    
    // 确认订单
    const confirmOrder = () => {
        console.log('确认订单');
        // console.log('props.value', props.value);
        if(props.value.status==4){
            message.info('订单已确认,不需要再确认')
        }else{
            confirmOrderById({
                orderId:props.value.orderId
            }).then(res=>{
                console.log('确认订单res',res);
                message.success('确认订单成功')
            }).catch(err=>{
                console.log('err345',err);
                message.success('服务器错误')
            })
        }
        
    }
    // 修改订单
    const updateOrder = () => {
        console.log('修改订单');
        setIsModalOpen(true)
    }
    // 关闭订单
    const closeOrder = () => {
        console.log('关闭订单');
        closeOrderById({
            orderId:props.value.orderId
        }).then(res=>{
            console.log('关闭订单res',res);
            message.success('关闭订单成功')
        }).catch(err=>{
            console.log('err345',err);
            message.success('服务器错误')
        })
    }
    // 关闭编辑框
    const close =()=>{
        setIsModalOpen(false)
    }
    return (
        <div>
            <Space className='btns'>
                <Button type='primary' onClick={confirmOrder}>确认订单</Button>
                <Button danger type="primary" onClick={updateOrder}>修改订单</Button>
                <Button onClick={closeOrder}>关闭订单</Button>
            </Space>
        {/* // 编辑订单的弹框 */}
            <EditOrderModal isModalOpen={isModalOpen} close={close } params={props.value}></EditOrderModal>
        </div>
    )
}